<template>
  <div class="app-container">
    <!-- app-container -->
    <div class="head">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="商品查询:" prop="">
          <el-input v-model="queryParams.query" placeholder="请输入商品ID/商品名称" clearable style="width: 300px" />
        </el-form-item>
        <el-form-item label="下单店铺：" prop="">
          <el-select v-model="queryParams.merchantIdList" placeholder="请选择" multiple clearable style="width: 240px">
            <el-option v-for="dict in merchantList" :key="dict.id" :label="dict.value" :value="dict.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态：" prop="">
          <el-select v-model="queryParams.status" placeholder="请选择" clearable style="width: 240px">
            <el-option v-for="dict in statusList" :key="dict.id" :label="dict.value" :value="dict.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="交易时间：" prop="">
          <el-date-picker v-model="date" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <export-excel-button title="商户兑换订单" :type="2" :size="'small'" action="/merchant/exchange/goods/order/v1/list/export"
          :params="ExportParams" />
      </div>
      <el-table v-loading="loading" :data="tabList" stripe border>
        <el-table-column label="序号" align="center" type="index" width="64px" />
        <el-table-column label="商品ID" align="center" prop="goodsId" :show-overflow-tooltip="true" />
        <el-table-column label="交易单号" align="center" prop="orderNo" :show-overflow-tooltip="true"  width="120"/>
        <el-table-column label="商品名称" align="center" prop="name" :show-overflow-tooltip="true" />
        <el-table-column label="下单店铺" align="center" prop="shopName" :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column label="下单用户" align="center" prop="merchantName" :show-overflow-tooltip="true" />
        <el-table-column label="联系方式" align="center" prop="phone" width="120" />
        <el-table-column label="交易积分" align="center" prop="payAmount" :show-overflow-tooltip="true" />
        <el-table-column label="订单状态" align="center" prop="statusDict" :show-overflow-tooltip="true" />
        <el-table-column label="下单时间" align="center" prop="createTime" :show-overflow-tooltip="true" width="120" />
        <el-table-column label="操作时间" align="center" prop="operateTime" :show-overflow-tooltip="true" />
        <el-table-column label="备注" align="center" prop="remark" width="240px" />
        <el-table-column label="操作" align="center" width="140" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 5">
              <el-button size="mini" type="text" @click="confirmOrder(scope.row,'confirm')">确认订单</el-button>
              <el-button size="mini" type="text" @click="confirmOrder(scope.row,'cancel')">取消订单</el-button>
            </div>
            <div v-else>-</div>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <Dialog :id="id" :pathType="pathType" v-bind="$attrs" v-if="dialogVisible" :visible.sync="dialogVisible" @success="_handleSuccess">
    </Dialog>
  </div>
</template>

<script>
import { orderList,shopSelectDown } from "@/api/merchants/exchangeOrder";
  import Dialog from "@/views/merchants/exchangeOrder/components/dialog"
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  export default {
    name: "",
    components: {
      Dialog,
      ExportExcelButton
    },
    data() {
      return {
        //日期
        date: [],
        // 遮罩层
        loading: false,
        dialogVisible: false,
        // 导出遮罩层
        exportLoading: false,
        // 总条数
        total: 0,
        // 表格数据
        tabList: [],
        id: '',
        pathType: 'confirm',//取消 cancel
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          merchantIdList: [], //商家id
          endDate: '', //交易时间结束
          query: '', //商品ID/商品名称
          startDate: '', //交易时间开始
          status:'',//订单状态
        },
        statusList:[],//订单状态下拉
        merchantList: [],//店铺下拉
      };
    },
    computed: {
      ExportParams() {
        const params = {
          ...this.queryParams,
        };
        return params;
      },
    },
    created() {
      if(this.$route.query.phone){
        this.queryParams.query = this.$route.query.phone;
      }
      this.getDict();
      this.getList();
      this.getMerchant()
    },
    methods: {
      //获取状态字典
      getDict() {
        var dictType = "merchant_exchange_goods_order_status";
        this.$getSelectList(dictType)
          .then((res) => {
            var arr = [{
              id: "",
              value: "全部",
            }, ];
            this.statusList = arr.concat(res.result[0].dictList);
            console.log('this.statusList',this.statusList)
          })
          .finally(() => {
            this.loading = false;
          });
      },
      /* 店铺下拉 */
      getMerchant(){
        shopSelectDown().then(response => {
          this.merchantList = response.result
        });
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        orderList(this.queryParams).then(response => {
          response.result.records.forEach(item => {
            for (var key in item) {
              if (!item[key]) {
                item[key] = "-";
              }
            }
          });
          this.tabList = response.result.records;
          this.total = response.result.total;
          this.loading = false;
        });
      },
      // 表单重置
      reset() {
        this.date = []
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          changeType: '', //兑换类型 1实物 2NTR 3线上权益 bee_integral_commodity_type
          endDate: '', //交易时间结束
          query: '', //用户名称/手机号/商品名称
          startDate: '', //交易时间开始
          payType: '',
          status:''
        }
        // this.resetForm("form");
        this.handleQuery()
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.startDate = this.date[0];
        this.queryParams.endDate = this.date[1];
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        // this.resetForm("queryForm");
        this.reset();
      },
      //新增
      confirmOrder(row,pathType) {
        this.id = row.id
        this.dialogVisible = true;
        this.pathType = pathType
      },
      // 编辑
      editClick(row) {
        this.dialogVisible = true;
      },
      _handleSuccess(e) {
        //成功回调
        // this.resetQuery()
        this.getList()
      },
    }
  };

</script>
<style scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .listBox_head {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 20px;
  }

</style>
